<template>
    <div>
        <h1>康复理疗信息显示</h1>
        <a href="/adds">理疗新增</a>
    </div>
    项目名称<input type="text" v-model="pagedata.name">
    <input type="button" value="查询" @click="show">
    <table class="table">
        <thead>
            <tr>
                <td><input type="checkbox" v-model="chks" @change="checkselect"></td>
                <td>Id</td>
                <td>项目名称</td>
                <td>项目编号</td>
                <td>佣金</td>
                <td>人数</td>
                <td>时长</td>
                <td>项目说明</td>
                <td>状态</td>
                <td>是否删除</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="d in data">
                <td><input type="checkbox" v-model="idarray" :value="d.Id"></td>
                <td>{{d.Id}}</td>
                <td>{{d.HelthName}}</td>
                <td>{{d.Bh}}</td>
                <td>{{d.Money}}</td>
                <td>{{d.People}}</td>
                <td>{{d.Hour}}</td>
                <td>{{d.Xm}}</td>
                <td>{{d.State==1?"启用":"禁用"}}</td>
                <td>{{d.IsDelete}}</td>
            </tr>
        </tbody>
    </table>
    一共{{countdata.countpage}}页，每页{{pagedata.pagesize}}条,一共{{countdata.count}}条,当前第{{pagedata.pageindex}}页
    <input type="button" @click="pageindex(1)" value="首页">
    <input type="button" @click="pageindex(2)" value="上一页">
    <input type="number" v-model="pagedata.pageindex" style="width: 50px;"> <input type="button" value="跳转" @click="skip">
    <input type="button" @click="pageindex(3)" value="下一页">
    <input type="button" @click="pageindex(4)" value="尾页">
    <input type="button" value="批量删除" @click="del">
    <input type="button" value="批量修改状态" @click="upd">
    {{idarray}}
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue';
onMounted(() => {
    show();
})
const chks=ref()
const idarray=ref([]);
const skip=()=>{
    show();
}
const upd=()=>{
    axios.get("/api/Health/UpdateRangeState",{params:{idstring:idarray.value.toString()}}).then(res=>{
        if(res.data>0)
        {
            alert('修改成功');
            show();
        }
        else
        {
            alert('修改失败')
            show();
        }
    })
}
const checkselect=()=>{
    idarray.value=[];
    if(chks.value)
    {
        data.value.forEach((e)=>{
            idarray.value.push(e.Id)
        })
    }
}
const del=()=>{
    if(confirm('您确定要删除吗?'))
    {
        axios.get("/api/Health/DeleteRangeHealth",{params:{idstring:idarray.value.toString()}}).then(res=>{
        if(res.data>0)
        {
            alert('删除成功')
            show();
        }
        else
        {
            alert('删除失败')
            show();
        }
    })
    }
    
}
const pageindex=(val:number)=>{
    if(val==1)
    {
        pagedata.value.pageindex=1;
        show();
    }
    if(val==2 && pagedata.value.pageindex>=1)
    {
        pagedata.value.pageindex--;
        show();
    }
    if(val==3 && pagedata.value.pageindex<countdata.value.countpage)
    {
        pagedata.value.pageindex++;
        show();
    }
    if(val==4)
    {
        pagedata.value.pageindex=countdata.value.countpage;
        show();
    }
}
const data=ref([{
    "Id": 0,
      "HelthName": "",
      "Bh": "",
      "Money": 0,
      "People": 0,
      "Hour": 0,
      "Xm": "",
      "State": 0,
      "IsDelete": true
}])
const pagedata=ref({
    name:'',
    pageindex:1,
    pagesize:5
})
const countdata=ref({
    count:0,
    countpage:0
})
const show=()=>{
    axios.get("/api/Health/HealthShow",{params:pagedata.value}).then(res=>{
        data.value=res.data.Members;
        countdata.value.count=res.data.Count;
        countdata.value.countpage=Math.ceil(countdata.value.count/pagedata.value.pagesize);
    })
}
</script>

<style scoped>

</style>